package com.zjdiepu.www.manage.view;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.enums.status.CarinfoEditStatus;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.commpent.ViewScopeControllerHelper;
import com.zjdiepu.www.commpent.mapper.other.OtherAuditInfoVoMapper;
import com.zjdiepu.www.commpent.mapper.yw.YwCarinfoEditHisVoMapper;
import com.zjdiepu.www.commpent.mapper.yw.YwCarinfoEditVoMapper;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.other.IOtherAuditInfoService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.ibiz.yw.IYwCarinfoEditHisService;
import com.zjdiepu.www.ibiz.yw.IYwCarinfoEditService;
import com.zjdiepu.www.model.other.dto.OtherAuditInfo;
import com.zjdiepu.www.model.other.ext.OtherAuditInfoExt;
import com.zjdiepu.www.model.yw.dto.YwCarinfoEdit;
import com.zjdiepu.www.model.yw.dto.YwCarinfoEditHis;
import com.zjdiepu.www.util.ExceptionHelper;

@Controller
@RequestMapping(value= "YwCarinfoEditViewController", produces="text/html;charset=UTF-8")
@Api(tags = {"修改贷款信息"}, produces="text/html;charset=UTF-8")
public class YwCarinfoEditViewController extends BaseController{

	@Resource
    private ICachedDictionaryService cachedDictionaryService;
    @Resource
    private ViewScopeControllerHelper viewScopeControllerHelper;
    @Resource
    private IYwBusinessService ywBusinessService;
    @Resource
    private IYwCarinfoEditService ywCarinfoEditService;
    @Resource
    private IYwCarinfoEditHisService ywCarinfoEditHisService;
    @Resource
    private YwCarinfoEditVoMapper ywCarinfoEditVoMapper;
    @Resource
    private YwCarinfoEditHisVoMapper ywCarinfoEditHisVoMapper;
    @Resource
    private IOtherAuditInfoService otherAuditInfoService;
    @Resource
    private OtherAuditInfoVoMapper otherAuditInfoVoMapper;
	
	@ApiOperation(value = "修改车辆信息", response = Boolean.class, httpMethod="GET", tags={"修改车辆信息"})
    @RequestMapping(value = "ywCarinfoEditDetail", method = RequestMethod.GET)
    public String ywCarinfoEditDetail(Model model, String busiId) {
    	if (StringUtils.isBlank(busiId)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	
    	model.addAttribute("carCategory", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColor", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	model.addAttribute("carType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_TYPE,"请选择..."));
    	
    	viewScopeControllerHelper.preparedBusiness(busiId, model);
    	viewScopeControllerHelper.preparedNowTime(model);
    	return "system/yw/ywCarinfoEditDetail";
    }
	
	@ApiOperation(value = "修改车辆信息审核", response = Boolean.class, httpMethod="GET", tags={"修改车辆信息审核"})
    @RequestMapping(value = "ywCarinfoEditShDetail", method = RequestMethod.GET)
    public String ywCarinfoEditShDetail(Model model, String busiId) {
    	if (StringUtils.isBlank(busiId)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	viewScopeControllerHelper.preparedBusiness(busiId, model);
	    viewScopeControllerHelper.preparedNowTime(model);
	    
	    YwCarinfoEdit ywCarinfoEdit = new YwCarinfoEdit();
	    ywCarinfoEdit.setDpStatus(DpStatus.NORMAL.getCode());
	    ywCarinfoEdit.setBusiId(busiId);
	    ywCarinfoEdit.setCarinfoEditStatus(CarinfoEditStatus.DAI_SHE_HE.getCode());
	    ywCarinfoEdit = ywCarinfoEditService.selectRefined(ywCarinfoEdit);
	    ywCarinfoEditVoMapper.mapper(ywCarinfoEdit);
	    model.addAttribute("ywCarinfoEdit", ywCarinfoEdit);
	    if(null != ywCarinfoEdit) {
	    	YwCarinfoEditHis ywCarinfoEditHis = new YwCarinfoEditHis();
	    	ywCarinfoEditHis.setDpStatus(DpStatus.NORMAL.getCode());
	    	ywCarinfoEditHis.setBusiId(busiId);
	    	ywCarinfoEditHis.setEditId(ywCarinfoEdit.getId());
	    	ywCarinfoEditHis = ywCarinfoEditHisService.selectRefined(ywCarinfoEditHis);
	    	ywCarinfoEditHisVoMapper.mapper(ywCarinfoEditHis);
	    	model.addAttribute("ywCarinfoEditHis", ywCarinfoEditHis);
	    }
	    
    	return "system/yw/ywCarinfoEditShDetail";
    }
	
	@ApiOperation(value = "修改车辆历史信息", response = Boolean.class, httpMethod="GET", tags={"修改车辆历史信息"})
    @RequestMapping(value = "ywCarinfoEditHisDetail", method = RequestMethod.GET)
    public String ywCarinfoEditHisDetail(Model model, String busiId, String editId) {
    	if (!StringUtils.isNoneBlank(busiId,editId)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	viewScopeControllerHelper.preparedBusiness(busiId, model);
	    
	    YwCarinfoEdit ywCarinfoEdit = ywCarinfoEditService.selectById(editId);
	    ywCarinfoEditVoMapper.mapper(ywCarinfoEdit);
	    model.addAttribute("ywCarinfoEdit", ywCarinfoEdit);
	    if(null != ywCarinfoEdit) {
	    	YwCarinfoEditHis ywCarinfoEditHis = new YwCarinfoEditHis();
	    	ywCarinfoEditHis.setDpStatus(DpStatus.NORMAL.getCode());
	    	ywCarinfoEditHis.setBusiId(busiId);
	    	ywCarinfoEditHis.setEditId(ywCarinfoEdit.getId());
	    	ywCarinfoEditHis = ywCarinfoEditHisService.selectRefined(ywCarinfoEditHis);
	    	ywCarinfoEditHisVoMapper.mapper(ywCarinfoEditHis);
	    	model.addAttribute("ywCarinfoEditHis", ywCarinfoEditHis);
	    }
	    
	    OtherAuditInfoExt otherAuditInfoExt = new OtherAuditInfoExt();
    	otherAuditInfoExt.withOutPage();
    	otherAuditInfoExt.setBaseWhere();
    	otherAuditInfoExt.setBusiId(busiId);
    	otherAuditInfoExt.setModeId( ModeIDType.CLXXXGSH.getCode());
    	otherAuditInfoExt.setOrderSql(" `CREATED` DESC");
    	List<OtherAuditInfo> otherAuditInfos = otherAuditInfoService.selectByExt(otherAuditInfoExt);
    	otherAuditInfoVoMapper.mapper(otherAuditInfos);
    	model.addAttribute("otherAuditInfos", otherAuditInfos);
	    
    	return "system/yw/ywCarinfoEditHisDetail";
    }
}
